<?php  
session_start();
include("../connect.php");
header('content-type:text/html;charset=utf-8');  
?>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
		 crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
		 crossorigin="anonymous"></script>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
		 crossorigin="anonymous">
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
		 crossorigin="anonymous"></script>
	</head>
	<body>
<?php
if ($_GET['action'] == 'login')
{
 $username=$_POST['name'];
$pwd=$_POST['pwd'];
$sql=mysqli_query($conn,"select * from admin where username='".$username."' and pwd='".$pwd."'");
$info=mysqli_fetch_array($sql);
if($info==true)
 {
$_SESSION['username']=$username; 
  $_SESSION['pwd']=$pwd; 
    echo "<script>alert('恭喜，登录成功!');window.location='admin.php';</script>";
    exit;
 }
 else
 { 
   echo "<script>alert('用户名或者密码错误!');window.location='login.php';</script>";
 }
}
?>
<?php 
	if($_SESSION['username']!=''){
		?>
		<div class="card bg-dark text-white">
			<img src="../img/admin-b.jpg" class="card-img">
			<div class="card-img-overlay">
			  <h5 class="card-title">后台登录</h5>
			  <div class="row" style="height: 100px;">
				  </div>
			  <div class="row">
				  <div class="col">
				  </div>
				  <div class="col">
							请退出您的用户账号
					  <a class="btn btn-outline-primary" href="../index.php" role="button">返回首页</a>
				  </div>
				  <div class="col">
				  </div>
			  </div>
			</div>
		  </div>

	<?php
	}else{
?>
<div class="card bg-dark text-white">
  <img src="../img/admin-b.jpg" class="card-img">
  <div class="card-img-overlay">
    <h5 class="card-title">后台登录</h5>
	<div class="row" style="height: 100px;">
		</div>
    <div class="row">
		<div class="col">
		</div>
		<div class="col">
			<form method="post" name="login" action="login.php?action=login">
			  <div class="form-group">
			    <label for="exampleFormControlInput1" class="text-body">用户名:</label>
			    <input type="text" name="name" class="form-control" required="required" id="exampleFormControlInput1" >
			  </div>
			  <div class="form-group">
			    <label for="exampleFormControlTextarea1" class="text-body">密码：</label>
			 <input type="password" name="pwd" class="form-control" required="required" id="exampleFormControlTextarea1"  >
			  </div>
			  <div class="form-group">
			  	 <button type="submit" class="btn btn-primary mb-2">登录</button>
			  </div>
			</form>
			<a class="btn btn-outline-primary" href="../index.php" role="button">返回首页</a>
		</div>
    	<div class="col">
    	</div>
    </div>
  </div>
</div>
<?php
	}
	?>
</body>